# 绘画图表

from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches


def use_bai():
    ppt = Presentation()
    # 添加幻灯片
    slide = ppt.slides.add_slide(ppt.slide_layouts[6])
    # 封装图标数据
    chart_data = CategoryChartData()
    # 分组数据
    chart_data.categories = ['第一季度', '第二季度', '第三季度', '第四季度']
    # 具体数据
    chart_data.add_series('2020', (19, 23, 45, 10))
    chart_data.add_series('2021', (17, 18, 22, 9))
    chart_data.add_series('2022', (21, 22, 40, 11))

    # 绘制图表 -- 柱状图
    x = Inches(1)
    y = Inches(1)
    cx = Inches(8)
    cy = Inches(5)
    slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data)

    ppt.save('../02.py_pptFile/04.ppt绘制图表.pptx')


if __name__ == '__main__':
    use_bai()
